<?php 
namespace Home\Controller;
use HDPHP\Library\Controller;

/*
 * 前台列表页控制器->继承公共控制器
 */

class ListController extends CommonController{
	
	public function index(){
//		z($_GET['cid']);
		//获取分类的子集
		$cid =isset($_GET['cid'])?(int)$_GET['cid']:"0";
		$sql ="SELECT * FROM hd_category WHERE pid={$cid}";
		$sonData =M()->query($sql);
		//如果该分类下面没有子集，则在当前级别
		if(!$sonData){
			$sql="SELECT pid FROM hd_category WHERE cid={$cid}";
			$pid =M()->query($sql);
			$pid =$pid[0]['pid'];
			//找同级兄弟分类sql语句
			$sql ="SELECT * FROM hd_category WHERE pid={$pid}";
			//执行语句得出结果集
			$sonData =M()->query($sql);
		}
//		z($sonData);
//		分配变量到模板页面
		$this->assign('sonData',$sonData);
		
//		//各种类型的问题
		$w = isset($_GET['w'])?(int)$_GET['w']:0;
		 
		 switch ($w) {
		 	//待解决
		 	case 0:
		 	$where ="solve=0 AND c.cid={$cid}";
		 		break;
		 	//已解决
		 	case 1:
		 	$where ="solve=1 AND c.cid={$cid}";
				
		 		break;
			//高悬赏
			case 2:
		 	$where ="reward AND c.cid={$cid}";
		 		break;	
			//全部待解决	
			case 5:
		 	$where ="solve=0";
		 		break;
			//全部已解决
			case 6:
		 	$where ="solve=1";
		 		break;
			//全部悬赏	
			case 7:
		 	$where ="reward>0";
		 		break;
			//全部零回答	
			case 8:
		 	$where ="answer=0";
		 		break;			
			//零回答	
		 	default:
		 	$where ="answer=0 AND c.cid={$cid}";
		 		break;
		 }
		$sql ="SELECT * FROM hd_ask as a JOIN hd_category as c ON a.cid=c.cid WHERE {$where}";
		//得到每个不同的数据
		$data = M()->query($sql);
//		z($data);		
		$this->assign('data',$data);
		
		
		/*
		 * 获得title
		 */
		if($cid=="0"){
//			$titledata=array();
			$titledata['title']="问题库-全部分类";
			$this->assign('titledata',$titledata);
		}else{
			$titlesql ="SELECT * FROM hd_category WHERE cid={$cid}";
		//得到当前标题名字
			$titledata =M()->query($titlesql);
			$titledata =$titledata[0];
			//数据传过去
//		z($titledata);
		$this->assign('titledata',$titledata);
		}
		
		
		
		
		
		//传递右侧用户和最高数据
		$this->IndexRight();
		//传递公共导航分类数据
		$this->TopMenu();
		//传递公共面包屑数据
		$this->TopNav();
		//传递公共导航提问总数		
		$this->AskCount();
		//载入列表页模板
		$this->display();
	}
	
	 
}





